<template>
	<view class="inwardPlanAdd">
		<uni-nav-bar color="#ffffff" background-color="#00aded" :statusBar="true" title="授权承运商" fixed="true" />
		<view class="inwardPlanAdd_top"></view>
		<view class="inwardPlanAdd_main">
			<dil-grad-form
				:stepOptions="stepOptions"
				:stepActive="stepActive"
				:formList="formList"
				:formValue="formValue"
				@next="next"
				@previous="previous"
				@cancelForm="cancelForm"
				@submitGradForm="submitGradForm"
			></dil-grad-form>
		</view>
		<view class="inwardPlanAdd_floot"></view>
	</view>
</template>

<script>
import { mapState, mapMutations } from 'vuex';
export default {
	data() {
		return {
			navBarTitle: '',
			stepOptions: [{ title: '主体信息' }, { title: '物流信息' }],
			stepActive: 0,
			formList: [
				{
					formId: 614,
					formValue: {}
				},
				{
					formId: 615,
					formValue: {}
				}
			],
			formValue: {},
			submitFormValue: {
				carrierId: '',
				materialId: '',
				insertUpdateRemark: '',
				materialNumber: '',
				materialWeight: '',
				requirementChildId: '',
				serialNumber: '',
				transTruckNumber: ''
			}
		};
	},
	computed: {
		...mapState('inward', ['inwardAppointItem'])
	},
	onLoad(option) {
		this.formValue = this.inwardAppointItem;
	},
	onShow() {
		let pages = getCurrentPages();
		if (pages.length <= 1) {
			this.back();
		}
	},
	methods: {
		back() {
			uni.navigateTo({
				url: '/pages/transPlan/inwardPlanToCarrier'
			});
		},
		//步骤，上一步
		previous(index, form) {
			console.log('previousform: ', form);
			this.formValue = form;
			this.stepActive = index;
		},
		next(index, form) {
			console.log('nextform: ', form);
			this.formValue = form;
			this.stepActive = index;
		},
		//取消事件
		cancelForm(form) {
			console.log('cancelFormform: ', form);
			this.formValue = form;
			this.back();
			uni.showToast({
				title: '用户取消操作',
				icon: 'error',
				duration: 2000
			});
		},
		//提交事件
		async submitGradForm(form) {
			this.formValue = form;
			let map = {};
			map = { ...form };
			// Object.keys(this.submitFormValue).forEach((e) => {
			// 	map[e] = form[e] || this.submitFormValue[e];
			// });
			const res = await this.$myRequest({
				url: '/api/v1/ams/productionPlanAdd',
				data: map
			}).catch((err) => {
				uni.showToast({
					duration: 2000,
					title: err,
					icon: 'error'
				});
			});
			if (res.data.status == 'succeed') {
				console.log(res.data.message);
				uni.showToast({
					title: res.data.message,
					icon: 'success',
					duration: 2000
				});
				setTimeout(() => {
					this.back();
				}, 2100);
			} else {
				uni.showToast({
					title: res.data.message,
					icon: 'error',
					duration: 2000
				});
			}
		}
	}
};
</script>

<style></style>